package org.example.persistence.model;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class OuterThread implements Runnable {
    private int start;
    private int end;
    private CountDownLatch latch;

    public OuterThread(int start, int end, CountDownLatch latch) {
        this.start = start;
        this.end = end;
        this.latch = latch;
    }

    @Override
    public void run() {
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        for (int i = start; i < end; i++) {
            int innerTaskCount = 10;
            for (int j = 0; j < innerTaskCount; j += 2) {
                for (int k = 0; k < 2; k++) {
                    executorService.execute(new InnerThread(k, j, innerTaskCount));
                }
            }
            System.out.println("Thread " + Thread.currentThread().getId() + " complete outer thread task " + i);
        }
        latch.countDown();
    }
}
